﻿using System;
using System.Collections.Generic;
using System.Text;

 

namespace Open.Data.Persistence
{
    public class BinaryExpression : Expression
    {
        //Properties
        public Expression LeftExpression { get; set; }
        public Expression RightExpression { get; set; }
        public ExpressionOperator Operator { get; set; }

        //Constructors
        public BinaryExpression(Expression left, Expression right, ExpressionOperator op)
        {
            LeftExpression = left;
            RightExpression = right;
            Operator = op;
        }

        //Methods
        public override IEnumerable<IParameter> GetParameters()
        {
            foreach (IParameter parameter in LeftExpression.GetParameters())
            {
                yield return parameter;
            }
            foreach (IParameter parameter in RightExpression.GetParameters())
            {
                yield return parameter;
            }
        }

        public override void AppendHashCode(StringBuilder builder)
        {
            LeftExpression.AppendHashCode(builder);
            builder.Append(Operator);
            RightExpression.AppendHashCode(builder);
        }
    }
}
